package com.sikao.app.ui;

import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.sikao.app.R;
import com.sikao.app.app.MyApplication;
import com.sikao.app.ui.base.BaseActivity;
import com.sikao.app.utils.SharepreferenceUtil;
import com.sikao.app.view.ScrollLayout;
/**
 * 引导页
 */
public class GuidePageActivity extends BaseActivity implements com.sikao.app.view.ScrollLayout.OnViewChangeListener {

	private com.sikao.app.view.ScrollLayout mScrollLayout;
	private LinearLayout pointLLayout;
	private Button btn;
	private ImageView[] imgs;
	private int count;
	private int currentItem;
	private SharepreferenceUtil sp;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		setContentView(R.layout.activity_guide_page);
		super.onCreate(savedInstanceState);
		sp = SharepreferenceUtil.getInstance(MyApplication.getInstance());
		sp.putString("isFirst","no");
	}

	@Override
	protected void initData() {

	}

	@Override
	protected void initView() {
		mScrollLayout = (ScrollLayout) findViewById(R.id.ScrollLayout);
		btn = (Button) findViewById(R.id.button);
		pointLLayout = (LinearLayout) findViewById(R.id.llayout);
	}


	@Override
	protected void initListener() {
		btn.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent intent = new Intent();
				intent.setClass(GuidePageActivity.this,FirstActivity.class);
				startActivity(intent);
				finish();
			}
		});
		mScrollLayout.SetOnViewChangeListener(this);
	}

	@Override
	protected void init() {
		count = mScrollLayout.getChildCount();
		imgs = new ImageView[count];
		for (int i = 0; i < count; i++) {
			imgs[i] = (ImageView) pointLLayout.getChildAt(i);
			imgs[i].setEnabled(true);
			imgs[i].setTag(i);
		}
		currentItem = 0;
		imgs[currentItem].setEnabled(false);
	}

	@Override
	public void OnViewChange(int position) {
		setcurrentPoint(position);
	}

	private void setcurrentPoint(int position) {
		if (position < 0 || position > count - 1 || currentItem == position) {
			return;
		}
		imgs[currentItem].setEnabled(true);
		imgs[position].setEnabled(false);
		currentItem = position;
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		return true;
	}
}
